package org.yray.sip.creator;

import org.yray.sip.base.MsgType;
import org.yray.sip.server.SipSession;
import java.util.EnumMap;
import java.util.Map;

public abstract class MessageCreator {

    public abstract String createMsg(SipSession session);


    private static Map<MsgType,MessageCreator> creatorMap=new EnumMap<MsgType, MessageCreator>(MsgType.class);


    public static void addCreator(MsgType msgType,MessageCreator creator)
    {
        creatorMap.put(msgType,creator);
    }

    public static MessageCreator getCreator(MsgType msgType)
    {
        return creatorMap.get(msgType);
    }

    static {
        OK200Creator oK200Creator=new OK200Creator();
        RegisterCreator registerCreator=new RegisterCreator();
        UnauthorizedCreator unauthorizedCreator=new UnauthorizedCreator();
        //消息生成工场
        MessageCreator.addCreator(MsgType.UNAUTHORIZED, unauthorizedCreator);
        MessageCreator.addCreator(MsgType.REGISTER,registerCreator);
        MessageCreator.addCreator(MsgType.OK, oK200Creator);
        MessageCreator.addCreator(MsgType.NOTIFY, oK200Creator);
        MessageCreator.addCreator(MsgType.INVITE, new InviteCreator());
        MessageCreator.addCreator(MsgType.ACK, new AckCreator());
        MessageCreator.addCreator(MsgType.BYE, new ByeCreator());
        MessageCreator.addCreator(MsgType.CANCEL, new CancelCreator());
        MessageCreator.addCreator(MsgType.INFO, new InfoCreator());
        MessageCreator.addCreator(MsgType.FORBIDDEN, new ForbiddenCreator());
        MessageCreator.addCreator(MsgType.PROGRESS183, new ProgressCreator());
    }
}
